// ==UserScript==
// @name         New Userscript
// @namespace    https://wm.xuanqingkj.cn/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @grant GM_xmlhttpRequest
// @match        https://wm.xuanqingkj.cn/*
// ==/UserScript==

(function() {

    function fetch_setp(offset){
        url='https://wm.xuanqingkj.cn/jrNJyBfHxQ.php/user/user/index?sort=user.id&order=asc&offset='+offset+'&limit=50&filter=%7B%7D&op=%7B%7D&_=1705663005663';
        url_target='http://127.0.0.1/index.php/index/SAVE?offset='+offset+'&t='+new Date().getTime();
        fetch(url, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'X-Requested-With': 'XMLHttpRequest',
            },
        })
            .then(response => {


                return response.json();
            })
            .then(data => {
                // 处理GET请求获取到的数据
                // ...
                console.log(data.rows.length);
                let req={
                    url:url_target,
                    method :"POST",
                    data:'data='+encodeURIComponent(JSON.stringify(data.rows)),
                    headers: {
                        "Content-type": "application/x-www-form-urlencoded"
                    },
                    onload:function(xhr){
                        console.log(xhr.responseText);
                        saveOffset=parseInt(xhr.responseText)
                        if(!isNaN(saveOffset) && 50==data.rows.length){
                            console.log('next'+saveOffset)
                            fetch_setp(offset+50)
                        }
                    }
                }
                GM_xmlhttpRequest(req);
                // 准备POST请求的数据


                // AJAX POST请求，同样包含特定请求头

            })
            .catch(error => {
                console.error('Error in GET request:', error);
            });
    }
    fetch_setp(0)
    // Your code here...
})();
